home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / regnpckg.sit / Picture MDEF ƒ / PicMDEF.c < prev    next >
C/C++ Source or Header  |  1990-12-10  |  2KB  |  80 lines

  1. #include "PicMDEF.h"
  2.  
  3. /* Build a new Picture Menu
  4.    Takes three arguments:
  5.       title:    Title of menu, will be truncated to 31 chars if longer
  6.       pic:        PicHandle for the menu picture
  7.       nrct:        Hanlde to an nrct defining the hot areas
  8.       
  9.    This routine assumes you'll be using HyperCard palettes and sets the
  10.    tBarHeight field to 12, change if using another window style
  11.    Sets the two hightlight fields to zero so no highlighting takes place
  12.  */
  13. MenuHandle NewPicMenu(title, pic, nrct)
  14. Str31 title; PicHandle pic; nrctHand nrct;
  15. {    PicMenuHandle mh;
  16.     register PicMenuPtr mp;
  17.     register int id;
  18.  
  19.     /* mh = (PicMenuHandle)NewHandle(sizeof(PicMenu));
  20.        HLock(mh);
  21.        mp = *mh; */
  22.     asm
  23.     {    move.l    #sizeof(PicMenu),d0
  24.         _NewHandle
  25.         move.l    a0,mh
  26.         _HLock
  27.         move.l    (a0),mp
  28.     }
  29.     
  30.     /* Apple's algorithm for free id */
  31.     id = 1023;
  32.     while( GetMHandle(++id) );
  33.     mp->menuID = id;
  34.     
  35.     asm
  36.     {    /* copy title */
  37.         move.l    title,a0
  38.         lea        OFFSET(PicMenu,menuTitle)(mp),a1
  39.         moveq    #32,d0
  40.         _BlockMove
  41.         /* truncate it too long */
  42.         move.b    OFFSET(PicMenu,menuTitle)(mp),d0
  43.         cmp.b    #31,d0
  44.         ble.s    @lenOk
  45.         move.b    #31,OFFSET(PicMenu,menuTitle)(mp)
  46.     lenOk:
  47.     }
  48.     
  49.     /* fill in other fields */
  50.     mp->enableFlags = -1;
  51.     mp->menuPic = pic;
  52.     mp->nrcts = nrct;
  53.     mp->hiOne = mp->hiTwo = 0;
  54.     mp->tBarHeight = 12; /* height of HC palette title bar */
  55.     mp->menuProc = GetNamedResource('MDEF', "\pPicture MDEF");
  56.     
  57.     asm
  58.     {    move.l    mh,a0
  59.         _HUnlock
  60.     }
  61.     
  62.     /* get Menu Manager to fill in size fields */
  63.     CalcMenuSize((MenuHandle)mh);
  64.     
  65.     return (MenuHandle)mh;
  66. }
  67.  
  68. /* Dispose a Picture Menu
  69.    This version releases the MDEF - don't do this if you have
  70.    multiple Picture menus!
  71.  */
  72. void DisposePicMenu(pm) MenuHandle pm;
  73. {    asm
  74.     {    move.l    pm,a0
  75.         move.l    (a0),a1
  76.         move.l    OFFSET(PicMenu, menuProc)(a1),-(a7)
  77.         _DisposHandle
  78.         _ReleaseResource
  79.     }
  80. }